/*
 * @Author: 13177709051 3506463075@qq.com
 * @Date: 2024-12-20 20:29:28
 * @LastEditors: 13177709051 3506463075@qq.com
 * @LastEditTime: 2024-12-20 20:44:27
 * @FilePath: /linux38/读写锁伪代码.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// uint32_t reader_count = 0;
// lock_t count_lock;
// lock_t writer_lock;


// // 加锁
// lock(count_lock);
// if(reader_count == 0)
//     lock(writer_lock);
// ++reader_count;
// unlock(count_lock);

// // read;

// //解锁
// lock(count_lock);
// --reader_count;
// if(reader_count == 0)
//     unlock(writer_lock);
// unlock(count_lock);


// lock(writer_lock);
// // write
// unlock(writer_lock);

// int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t *attr, intpref);
// /*
// pref 共有 3 种选择
// PTHREAD_RWLOCK_PREFER_READER_NP (默认设置) 读者优先，可能会导致写者饥饿情况
// PTHREAD_RWLOCK_PREFER_WRITER_NP 写者优先，目前有 BUG，导致表现行为和PTHREAD_RWLOCK_PREFER_READER_NP 一致
// PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP 写者优先，但写者不能递归加锁
// */

// int pthread_rwlock_init(pthread_rwlock_t *restrict rwlock,const pthread_rwlockattr_t *restrict attr);
// int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);


// int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
// int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
// int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);